﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace 医院药库管理系统
{
    public partial class 药品报损 : Form
    {
        public 药品报损()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {
           
            
        }

        private void 药品报损_Load(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;                             //在字符串变量中，描述连接字符串所需的服务器地址、数据库名称、集成安全性（即是否使用Windows验证）；
            SqlCommand sqlCommand = new SqlCommand();                                                       //声明并实例化SQL命令；
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandText = "SELECT * FROM tb_Out WHERE Remark='过期'or Remark='破损';";
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.SelectCommand = sqlCommand;
            DataTable csTable = new DataTable();
            sqlConnection.Open();
            sqlDataAdapter.Fill(csTable);
            sqlConnection.Close();
            this.dgv_bs.DataSource = csTable; 
            // TODO: 这行代码将数据加载到表“yyaoDataSet5.tb_Out”中。您可以根据需要移动或移除它。
            this.tb_OutTableAdapter.Fill(this.yyaoDataSet5.tb_Out);
            // TODO: 这行代码将数据加载到表“yyaoDataSet4.tb_Administrator”中。您可以根据需要移动或移除它。
            this.tb_AdministratorTableAdapter.Fill(this.yyaoDataSet4.tb_Administrator);
            int i = 0;
            Decimal sum = 0;
            while (i < this.dgv_bs.Rows.Count - 1)
            {

                sum = sum + Convert.ToDecimal(this.dgv_bs.Rows[i].Cells[7].Value) * Convert.ToDecimal(this.dgv_bs.Rows[i].Cells[8].Value);
                i++;
            }
            lb_sum.Text = sum.ToString();
            this.dgv_bs.Columns["No"].HeaderText = "编号";
            this.dgv_bs.Columns["MedicineName"].HeaderText = "名称";
            this.dgv_bs.Columns["Made_Date"].HeaderText = "生产日期";
            this.dgv_bs.Columns["Valid_Date"].HeaderText = "有效期至";
            this.dgv_bs.Columns["Acronym"].HeaderText = "首字母缩写";
            this.dgv_bs.Columns["FirmName"].HeaderText = "生产厂商";
            this.dgv_bs.Columns["OutOfDate"].HeaderText = "出库时间";
            this.dgv_bs.Columns["Price"].HeaderText = "价格";

            this.dgv_bs.Columns["DosageForm"].HeaderText = "物理状态";
           
            this.dgv_bs.Columns["Principal"].HeaderText = "负责人";
            this.dgv_bs.Columns["OutOfQuantity"].HeaderText = "数量";
            this.dgv_bs.Columns["Remark"].HeaderText = "出库去向";
            
        }

        private void bt_qd_Click(object sender, EventArgs e)
        {
           SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;                             //在字符串变量中，描述连接字符串所需的服务器地址、数据库名称、集成安全性（即是否使用Windows验证）；
            SqlCommand sqlCommand = new SqlCommand();                                                       //声明并实例化SQL命令；
            sqlCommand.Connection = sqlConnection;

                sqlCommand.CommandText = "SELECT * FROM tb_Out WHERE OutOfDate=@OutOfDate and Principal Like '%'+@Principal+'%';";

                sqlCommand.Parameters.AddWithValue("@OutOfDate", this.dtp_ckrq.Value);
                sqlCommand.Parameters.AddWithValue("@Principal", this.cb_fzr.Text.Trim());
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
                sqlDataAdapter.SelectCommand = sqlCommand;
                DataTable csTable1 = new DataTable();
                
                sqlConnection.Open();
                sqlDataAdapter.Fill(csTable1);
                sqlConnection.Close();
                this.dgv_bs.DataSource = csTable1;
                int i = 0;
                Decimal sum = 0;
                while (i < this.dgv_bs.Rows.Count - 1)
                {
                    
                    sum = sum + Convert.ToDecimal(this.dgv_bs.Rows[i].Cells[7].Value) * Convert.ToDecimal(this.dgv_bs.Rows[i].Cells[8].Value);
                    i++;
                }
                lb_sum.Text = sum.ToString();
               
           
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
